package com.zbxx.container.websocket.service;

import com.zbxx.container.websocket.entity.User;
import com.zbxx.container.websocket.repository.JpaUserRepository;
import com.zbxx.container.websocket.repository.MybatisMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author 万仁杰
 * @date 2019/05/22
 */
@Service
public class UserService {


    @Autowired
    private JpaUserRepository jpaUserRepository;

    @Resource
    private MybatisMapper mybatisMapper;

    @Transactional(rollbackFor = Exception.class)
    public void insertUserByMybatis(User user){
        mybatisMapper.insertUser(user);
        throw new RuntimeException("test transaction");
    }

    @Transactional(rollbackFor = Exception.class)
    public void insertUserByJpaRepository(User user){
        jpaUserRepository.save(user);
        throw new RuntimeException("test transaction");
    }

}
